$(function () {
    //抽取js变量
    var saleChart_datagrid = $("#saleChart_datagrid");
    var saleByBar_dialog = $("#saleByBar_dialog");
    saleChart_datagrid.datagrid({
        url:'/chart/saleChart/query.do',
        fitColumns:true,
        fit:true,//自动填充
        toolbar:'#saleChart_toolbar',
        pagination:true, //在DataGrid控件底部显示分页工具栏
        rownumbers:true, //显示一个行号列。
        singleSelect:true,//只允许选择一行
        striped:true, //显示斑马线效果
        columns:[[
            {field:'groupType',title:'分组类型',width:80},
            {field:'totalAmount',title:'销售总金额',width:80},
        ]],
    });

    var methodObj = {
        query : function(){
        var organization = $("#organization").val();
        var product = $("#product").val();
        var beginDate = $("#beginDate").val();
        var endDate = $("#endDate").val();
        var groupType = $("#groupType").val();
        saleChart_datagrid.datagrid("load",{
            safetymechanismId:organization,
            productId:product,
            beginDate:beginDate,
            endDate:endDate,
            groupType:groupType
            });
        },
        reload :function () {
            window.location.reload();
        },

        saleByBar: function () {
            var rows = saleChart_datagrid.datagrid("getRows")

            //设置src

            var organization = $("#organization").val();
            var product = $("#product").val();
            var beginDate = $("#beginDate").val();
            var endDate = $("#endDate").val();
            var groupType = $("#groupType").val();
            var str = '?organization=' +organization
            str += '&product=' +product
            str += '&beginDate=' +beginDate
            str += '&endDate=' +endDate
            str += '&groupType=' +groupType
            $("#barTable").prop("src","/chart/saleBybar/view.do"+ str )
            saleByBar_dialog.dialog({
                title:'销售报表',
                width:610,
                height:520,
            })


        },
        saleByPie: function () {
            var rows = saleChart_datagrid.datagrid("getRows")

            //设置src
            var organization = $("#organization").val();
            var product = $("#product").val();
            var beginDate = $("#beginDate").val();
            var endDate = $("#endDate").val();
            var groupType = $("#groupType").val();
            var str = '?organization=' +organization
            str += '&product=' +product
            str += '&beginDate=' +beginDate
            str += '&endDate=' +endDate
            str += '&groupType=' +groupType
            $("#pieTable").prop("src","/chart/saleByPie/view.do"+ str )
            $("#saleByPie_dialog").dialog({
                title:'销售报表',
                width:610,
                height:520,
            })
        }

    }

    $("a[data-cmd]").click(function () {
        var methodName = $(this).data("cmd");
        methodObj[methodName]();
    })

})










